//
//  COGiftView.swift
//  CocoProject
//
//  Created by Ruthless on 2023/8/23.
//

import UIKit
import QMUIKit

class COGiftView: UIView {
    var clickAction: (()->Void)?
    
    var sel: Bool = false {
        didSet {
            
            flowImageView.layer.borderWidth = sel ? 1 : 0
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func configUI() {
        addSubview(stackView)
        stackView.addArrangedSubview(flowImageView)
        stackView.addArrangedSubview(nameLabel)
        stackView.addArrangedSubview(moneyButton)
        
        stackView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        flowImageView.snp.makeConstraints { make in
            make.width.height.equalTo(80)
        }
    }
    
    private lazy var stackView: UIStackView = {
        let stackView = UIStackView()
        stackView.axis = .vertical
        stackView.alignment = .center
        stackView.spacing = 5
        return stackView
    }()
    
    private(set) lazy var flowImageView: UIImageView = {
        let imgV = UIImageView()
        imgV.layer.masksToBounds = true
        imgV.layer.cornerRadius = 10
        imgV.layer.borderColor = UIColor.rgba(152, 48, 255, 1).cgColor
        return imgV
    }()
    
    private(set) lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(14)
        label.textColor = .white
        return label
    }()
    
    private(set) lazy var moneyButton: QMUIButton = {
        let btn = QMUIButton()
        btn.setImage(UIImage(named: "金币"), for: .normal)
        btn.setTitleColor(.white, for: .normal)
        btn.titleLabel?.font = .regular(12)
        btn.spacingBetweenImageAndTitle = 3
        btn.isUserInteractionEnabled = false
        return btn
    }()
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        clickAction?()
    }
}
